package com.example.mall.web.controller;

import com.example.mall.dto.MessageTypesDto;
import com.example.mall.exception.ErrorEnumCode;
import com.example.mall.exception.GlobalCustomerException;
import com.example.mall.query.PageDTO;
import com.example.mall.service.IMessageTypesService;
import com.example.mall.domain.MessageTypes;
import com.example.mall.query.MessageTypesQuery;
import com.example.mall.result.JSONResult;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/messageTypes")
public class MessageTypesController {

    @Autowired
    public IMessageTypesService messageTypesService;

    /**
     * 分页查询消息类型表信息
     * @param messageTypesQuery
     * @return
     */
    @GetMapping("queryPage")
    @ApiOperation(value = "分页查询消息类型表信息",notes = "分页查询消息类型表信息",httpMethod = "GET")
    public JSONResult queryPage(MessageTypesQuery messageTypesQuery){
        PageDTO<MessageTypesDto> messageTypesDtoPageDTO = messageTypesService.queryPage(messageTypesQuery);
        return JSONResult.success("查询成功",messageTypesDtoPageDTO);
    }

    /**
     * 根据id查询消息类型表信息
     * @param typeId
     * @return
     */
    @GetMapping("query/{typeId}")
    @ApiOperation(value = "根据id查询消息类型表信息",notes = "根据id查询消息类型表信息",httpMethod = "GET")
    public JSONResult query(@PathVariable("typeId")Long typeId){
        //1.根据id查询用户信息
        if (typeId == null){
            throw new GlobalCustomerException(ErrorEnumCode.TYPEID_NOT_ID);
        }
        MessageTypes messageTypes = messageTypesService.getById(typeId);
        return JSONResult.success("查询成功",messageTypes);
    }

    /**
     * 根据id查询消息类型表信息
     * @param typeId
     * @return
     */
    @GetMapping("queryMessageTypesById/{typeId}")
    @ApiOperation(value = "根据id查询消息类型表信息",notes = "根据id查询消息类型表信息",httpMethod = "GET")
    public JSONResult queryMessageTypesById(@PathVariable("typeId")Long typeId){
        //1.根据id查询用户信息
        if (typeId == null){
            throw new GlobalCustomerException(ErrorEnumCode.TYPEID_NOT_ID);
        }
        MessageTypes messageTypes = messageTypesService.queryMessageTypesById(typeId);
        return JSONResult.success("查询成功",messageTypes);
    }

    /**
     * 查询全部消息类型表信息
     * @param
     * @return
     */
    @GetMapping("queryMessageTypesList")
    @ApiOperation(value = "查询全部消息类型表信息",notes = "查询全部消息类型表信息",httpMethod = "GET")
    public JSONResult queryMessageTypesList(){
        List<MessageTypes> messageTypes = messageTypesService.queryMessageTypesList();
        return JSONResult.success("查询成功",messageTypes);
    }

    /**
     * 新增消息类型表
     * @param messageTypesDto
     * @return
     */
    @PostMapping("insert")
    @ApiOperation(value = "新增消息类型表",notes = "新增消息类型表",httpMethod = "POST")
    public JSONResult insert(@RequestBody MessageTypesDto messageTypesDto){
        messageTypesService.insert(messageTypesDto);
        return JSONResult.success("保存成功");
    }

    /**
     * 修改消息类型表信息
     * @param messageTypesDto
     * @return
     */
    @PostMapping("update")
    @ApiOperation(value = "修改消息类型表信息",notes = "修改消息类型表信息",httpMethod = "POST")
    public JSONResult update(@RequestBody MessageTypesDto messageTypesDto){
        messageTypesService.update(messageTypesDto);
        return JSONResult.success("修改成功");
    }

    /**
     * 删除消息类型表信息
     * @param typeId
     * @return
     */
    @PostMapping("delete/{typeId}")
    @ApiOperation(value = "删除消息类型表信息",notes = "删除消息类型表信息",httpMethod = "POST")
    public JSONResult delete(@PathVariable("typeId") Long typeId) {
        messageTypesService.delete(typeId);
        return JSONResult.success("删除成功");
    }

    /**
     * 批量删除消息类型表信息
     * @param typeIds
     * @return
     */
    @PostMapping("deleteBatch")
    @ApiOperation(value = "批量删除消息类型表信息",notes = "批量删除消息类型表信息",httpMethod = "POST")
    public JSONResult deleteAll(@RequestBody List<Long> typeIds) {
        messageTypesService.deleteBatch(typeIds);
        return JSONResult.success("批量删除成功");
    }
}
